#!/usr/bin/perl
# 
# Exercise 8.1
# 
# Write a subroutine that checks a string and returns true if it's a DNA sequence. 
# Write another that checks for protein sequence data.
#
# Answer to Exercise 8.1

# Note that some other answers may be useful.  For instance, often DNA is written
# with the bases A C G T plus the N for "unknown".

sub isDNA {

	my($sequence) = @_;

	# If there's a non-ACGT (case-insensitive) character, return "false"
	# Recall that ^ at the beginning of a character class means "any character
	# other than the ones listed"

	if($sequence =~ /[^ACGT]/i) { return 0; }

	# Otherwise, return "true"
	return 1;
}

# Here's another version that admits all the IUB/IUPAC nucleotide codes 
# (see Table 4-1 in Chapter 4)

sub isDNAiub {

	my($sequence) = @_;

	# If there's a non-base (case-insensitive) character, return "false"
	if($sequence =~ /[^ACGTUMRWSYKVHDBN]/i) { return 0; }

	# Otherwise, return "true"
	return 1;
}

# We'll just deal with the one-character IUB/IUPAC amino acid codes here
# (see Table 4-2 in Chapter 4)

sub isProtein {

	my($sequence) = @_;

	# If there's a non-amino acid (case-insensitive) character, return "false"
	if($sequence =~ /[^ACDEFGHIKLMNPQRSTVWXYZ]/i) { return 0; }

	# Otherwise, return "true"
	return 1;
}
